import request from '@/utils/request';

/**
 * 查询知识库列表
 *  /knowledge/list
 */
export async function queryKnowledgeList(
  data: { pageNum: number; pagesize: number },
  options?: API.baseOption,
) {
  return request<API.KnowledgeList>('/knowledge/list', {
    method: 'GET',
    data,
    ...(options || {}),
  });
}

/**
 * 查看知识库基础信息
 * /knowledge/{id}/detail
 */
export async function queryKnowledgeDetail(data: Record<'id', string>, options?: API.baseOption) {
  return request<API.KnowledgeDetail>(`/knowledge/${data.id}/detail`, {
    method: 'GET',
    ...(options || {}),
  });
}

/**
 * 保存知识库
 * /knowledge/save
 */
export async function saveKnowledge(data: API.KnowledgeDetail, options?: API.baseOption) {
  return request<API.TResult<null>>('/knowledge/save', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 *  删除知识库
 */
export async function deleteKnowledge(data: Record<'id', string>, options?: API.baseOption) {
  return request<API.TResult<null>>(`/knowledge/${data.id}/delete`, {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 查看知识库内容列表
 */
export async function queryKnowledgeListById(data: Record<'id', number>, options?: API.baseOption) {
  return request<API.KnowledgeListRes>(`/knowledge/${data.id}/list`, {
    method: 'GET',
    ...(options || {}),
  });
}

/**
 * 上传文件
 */
export async function uploadKnowledge(data: { file: string }, options?: API.baseOption) {
  return request<API.TResult<null>>(`/knowledge/upload`, {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 新增知识库内容
 */
export async function addDataKnowledge(data: API.KnowledgeDataDetail, options?: API.baseOption) {
  return request<API.TResult<null>>('/knowledge/addData', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 *  删除知识库内容
 */
export async function deleteDataKnowledge(data: Record<'id', number>, options?: API.baseOption) {
  return request<API.TResult<null>>(`/knowledge/deleteData/${data.id}`, {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 查看内容详情
 * /knowledge/{id}/detail
 */
export async function queryKnowledgeDataDetail(
  data: Record<'id', number>,
  options?: API.baseOption,
) {
  return request<API.KnowledgeListItemById>(`/knowledge/data/${data.id}`, {
    method: 'GET',
    ...(options || {}),
  });
}

/**
 * 读取网页内容
 * /knowledge/readUrl
 */
export async function readUrlKnowledge(data: Record<'url', string>, options?: API.baseOption) {
  return request<API.KnowledgeReadUrlDetail>(`/knowledge/readUrl`, {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 知识库管理员设置
 * /knowledge/saveManagerList
 */
export async function saveManagerList(data: API.SaveManagerListParam, options?: API.baseOption) {
  return request<API.TResult<null>>(`/knowledge/saveManagerList`, {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 查询可选择用户列表
 *  /knowledge/list
 */
export async function getListExcludeOwner(
  data: { id: string; type: string },
  options?: API.baseOption,
) {
  return request<API.KnowledgeOwnerList[]>('/user/getListExcludeOwner', {
    method: 'GET',
    data,
    ...(options || {}),
  });
}
